/*
 * @Description: 子组件
 * @Author: ruanyuesheng
 * @Date: 2020-09-03 16:10:06
 * @LastEditTime: 2022-04-01 15:00:25
 * @LastEditors: r_yuesheng
 */
import React, { Component } from 'react';
import { Button } from 'antd';
import PropTypes from 'prop-types';

class sonItem extends Component {
  state = {
    childrenText: '这是子组件传给父组件的'
  };
  clickFun(text) {
    this.props.emitText(text);
  }
  render() {
    return (
      <div>
        <h1>子组件内容</h1>
        <Button onClick={this.clickFun.bind(this, this.state.childrenText)}>
          更改为子组件标题
        </Button>
        <ul>
          {this.props.arr.map(item => {
            return (
              <li key={item.userName}>
                {item.userName} 评论是:{item.text}
              </li>
            );
          })}
        </ul>
        <span>我是父传的{this.props.temp}</span>
      </div>
    );
  }
}

sonItem.propTypes = {
  temp: PropTypes.string
};

export default sonItem;
